local zishucup__jieshuo = fk.CreateSkill{
  name = "zishucup__jieshuo",
}

Fk:loadTranslationTable{
  ["zishucup__jieshuo"] = "桀朔",
  [":zishucup__jieshuo"] = "每名其他角色限四次，其可以：出牌阶段开始时，视为对你使用【决斗】；或成为你使用【杀】的目标时，消耗所有剩余次数以转移至你攻击范围内另一名角色。",

  ["#zishucup__jieshuo-duel"] = "桀朔：是否视为对%dest使用决斗？（剩余次数%arg，发动后减1）",
  ["#zishucup__jieshuo-slash"] = "桀朔：是否将%dest对你使用的杀转移给其攻击范围内另一名角色？（剩余次数%arg，发动后减至0）",

  ["$zishucup__jieshuo1"] = "跋扈行于建宁，恩信著于南土！",
  ["$zishucup__jieshuo2"] = "朝廷欲征三千斫木，雍有梁林乎？",
}

zishucup__jieshuo:addEffect(fk.EventPhaseStart, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(zishucup__jieshuo.name) and target.phase == Player.Play 
    and target:getMark("zishucup__jieshuo_"..player.id) > 0 and target:canUseTo(Fk:cloneCard("duel"), player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(target, {
    skill_name = zishucup__jieshuo.name,
    prompt = "#zishucup__jieshuo-duel::"..player.id..":"..target:getMark("zishucup__jieshuo_"..player.id),
  })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(target, "zishucup__jieshuo_"..player.id, 1)
    local card = Fk:cloneCard("duel")
    card.skillName = zishucup__jieshuo.name
    local use = { from = target, tos = {player}, card = card}
    room:useCard (use)
  end,
})

zishucup__jieshuo:addEffect(fk.TargetConfirming, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    return target ~= player and player:hasSkill(zishucup__jieshuo.name) and data.card.trueName == "slash"
    and data.from == player and target:getMark("zishucup__jieshuo_"..player.id) > 0 
    and table.find(room:getOtherPlayers(target), function(p) return p ~= player and not player:isProhibited(p, data.card) and player:inMyAttackRange(p) end)
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askToChoosePlayers(target, {
      min_num = 1,
      max_num = 1,
      targets = table.filter(player.room:getOtherPlayers(target), function(p) return
        p ~= player and not player:isProhibited(p, data.card) and player:inMyAttackRange(p) end),
      skill_name = zishucup__jieshuo.name,
      cancelable = true,
      prompt = "#zishucup__jieshuo-slash::"..player.id..":"..target:getMark("zishucup__jieshuo_"..player.id),
    })
    if #to == 1 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, "zishucup__jieshuo_"..player.id, 0)
    local to = event:getCostData(self).tos[1]
    data:cancelTarget(target)
    data:addTarget(to)
  end,
})

zishucup__jieshuo:addAcquireEffect(function (self, player, is_start)
  for _, id in ipairs(player.room:getOtherPlayers(player)) do
    player.room:setPlayerMark(id, "zishucup__jieshuo_"..player.id, 4)
  end
end)

return zishucup__jieshuo
